package o2o.thridpost.dada.model.to;

import com.alibaba.fastjson.annotation.JSONField;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;
import o2o.company.model.ShopInfo;
import o2o.dao.PO.order.OrderInfo;
import o2o.utils.IPAddressUtil;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 新增达达订单
 *
 * @author sunyufan deporation@qq.com
 * @date 2021/4/29 13:54
 * @description: AddDadaOrderTO
 */
@Data
@NoArgsConstructor
public class AddDadaOrderTO implements Serializable {

    /**
     * 门店编号，门店创建后可在门店列表和单页查看
     */
    @JSONField(name = "shop_no")
    @SerializedName("shop_no")
    private String shopNo;

    /**
     * 第三方订单ID
     */
    @JSONField(name = "origin_id")
    @SerializedName("origin_id")
    private String originId;

    /**
     * 订单所在城市的code
     */
    @JSONField(name = "city_code")
    @SerializedName("city_code")
    private String cityCode;

    /**
     * 订单金额（单位：元）
     */
    @JSONField(name = "cargo_price")
    @SerializedName("cargo_price")
    private double cargoPrice;

    /**
     * 是否需要垫付 1:是 0:否 (垫付订单金额，非运费)
     */
    @JSONField(name = "is_prepay")
    @SerializedName("is_prepay")
    private Integer isPrepay;

    /**
     * 收货人姓名
     */
    @JSONField(name = "receiver_name")
    @SerializedName("receiver_name")
    private String receiverName;

    /**
     * 收货人地址
     */
    @JSONField(name = "receiver_address")
    @SerializedName("receiver_address")
    private String receiverAddress;

    /**
     * 收货人地址纬度（高德坐标系，若是其他地图经纬度需要转化成高德地图经纬度)
     */
    @JSONField(name = "receiver_lat")
    @SerializedName("receiver_lat")
    private BigDecimal receiverLat;

    /**
     * 收货人地址经度（高德坐标系，若是其他地图经纬度需要转化成高德地图经纬度)
     */
    @JSONField(name = "receiver_lng")
    @SerializedName("receiver_lng")
    private BigDecimal receiverLng;

    /**
     * 收货人手机号（手机号和座机号必填一项）
     */
    @JSONField(name = "receiver_phone")
    @SerializedName("receiver_phone")
    private String receiverPhone;

    /**
     * 回调URL
     */
    @JSONField(name = "callback")
    @SerializedName("callback")
    private String callback;

    public AddDadaOrderTO(OrderInfo orderInfo, ShopInfo shopInfo, String cityCode) {
        this.shopNo = String.valueOf(shopInfo.getId());
        this.originId = orderInfo.getOrderNo();
        this.cityCode = cityCode;
        this.cargoPrice = orderInfo.getTotalPrice();
        this.isPrepay = 0;
        this.receiverName = orderInfo.getBuyer();
        this.receiverAddress = orderInfo.getAddress();
        this.receiverLat = BigDecimal.valueOf(orderInfo.getLat());
        this.receiverLng = BigDecimal.valueOf(orderInfo.getLng());
        this.receiverPhone = orderInfo.getTelephone();
        this.callback = IPAddressUtil.getLocalHost() + "/dada/order/handle";
    }
}
